﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="OpenQTP.aspx.cs" Inherits="OpenQTP" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Execute Batch...</title>
    <link href="styleMaster.css" type="text/css" rel="stylesheet"/>
    <link rel="stylesheet" type="text/css" href="css/subModal.css" />
    <script type="text/javascript" src="js/common.js"></script>
	<script type="text/javascript" src="js/subModal.js"></script>
<script language = "Javascript" type="text/javascript">
    function openExcelDocPath(strloc) {
        try {
            var objExcel;
            objExcel = new ActiveXObject("Excel.Application");
            objExcel.Visible = true;
            objExcel.Workbooks.Open(strloc, false, false);
        }
        catch (e) {
            alert('Error: '+ e.Message);
        }
    }

    function echeck(str) {
        var at="@"
	    var dot="."
	    var lat=str.indexOf(at)
	    var lstr=str.length
	    var ldot=str.indexOf(dot)
	    if (str.indexOf(at)==-1){
	       alert("Invalid E-mail ID")
	       return false
	    }

	    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	       alert("Invalid E-mail ID")
	       return false
	    }

	    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	        alert("Invalid E-mail ID")
	        return false
	    }

	     if (str.indexOf(at,(lat+1))!=-1){
	        alert("Invalid E-mail ID")
	        return false
	     }

	     if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	        alert("Invalid E-mail ID")
	        return false
	     }

	     if (str.indexOf(dot,(lat+2))==-1){
	        alert("Invalid E-mail ID")
	        return false
	     }
		
	     if (str.indexOf(" ")!=-1){
	        alert("Invalid E-mail ID")
	        return false
	     }

	     return true					
	  }

    function ValidateForm(){
     try {
	    var emailID=document.getElementById("txtEmail").value;
    	
	    if ((emailID==null)||(emailID=="")){
		    alert("Please Enter your Email ID");
		    return false;
	    }
	    else if (echeck(emailID)==false){
		    emailID="";
		    return false;
	    }
	    else{
	        vbFunc();
            alert("Email saved");
	    }
      }
      catch(e){
      alert('Error: '+e.Message)  
      }
     }
    </script>

<script src="js/jquery-1.5.2.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
            $(document).ready(function() {
                $("DIV.ContainerPanel > DIV.collapsePanelHeader > DIV.ArrowExpand").toggle(
                function() {
                    $(this).parent().next("div.Content").show("slow");
                    $(this).attr("class", "ArrowClose");
                },

                function() {                    
                    $(this).parent().next("div.Content").hide("slow");
                    $(this).attr("class", "ArrowExpand");
                });              
            });            
</script>

<script language="JavaScript" type="text/javascript">

    var duration=120 // Specify duration of progress bar in seconds
    var _progressWidth = 60;	// Display width of progress bar.

    var _progressBar = "|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"
    var _progressEnd = 5;
    var _progressAt = 0;


    // Create and display the progress dialog.
    // end: The number of steps to completion
    function ProgressCreate(end) {
	    // Initialize state variables
	    _progressEnd = end;
	    _progressAt = 0;
        window.document.getElementById('runbatchhyp').style.visibility="hidden";
	    // Move layer to center of window to show
	    if (document.all) {	// Internet Explorer
		    progress.className = 'show';
		    progress.style.left = (document.body.clientWidth/2) - (progress.offsetWidth/2);
		    progress.style.top = document.body.scrollTop+(document.body.clientHeight/2) - (progress.offsetHeight/2)+ 100 + "px";
	    } else if (document.layers) {	// Netscape
		    document.progress.visibility = true;
		    document.progress.left = (window.innerWidth/2) - 100+"px";
		    document.progress.top = pageYOffset+(window.innerHeight/2) - 40+"px";
	    } else if (document.getElementById) {	// Netscape 6+
		    document.getElementById("progress").className = 'show';
		    document.getElementById("progress").style.left = (window.innerWidth/2)- 100+"px";
		    document.getElementById("progress").style.top = pageYOffset+(window.innerHeight/2) - 40+"px";
	    }

	    ProgressUpdate();	// Initialize bar
    }

    // Hide the progress layer
    function ProgressDestroy() {
	    // Move off screen to hide
	    if (document.all) {	// Internet Explorer
	        progress.className = 'hide';
	    } else if (document.layers) {	// Netscape
		    document.progress.visibility = false;
	    } else if (document.getElementById) {	// Netscape 6+
		    document.getElementById("progress").className = 'hide';
	    }
    }

    // Increment the progress dialog one step
    function ProgressStepIt() 
    {
	    _progressAt++;
	    if(_progressAt > _progressEnd) _progressAt = _progressAt % _progressEnd;
	    ProgressUpdate();
    }

    // Update the progress dialog with the current state
    function ProgressUpdate() {
	    var n = (_progressWidth / _progressEnd) * _progressAt;
	    if (document.all) {	// Internet Explorer
		    var bar = dialog.bar;
 	    } else if (document.layers) {	// Netscape
		    var bar = document.layers["progress"].document.forms["dialog"].bar;
		    n = n * 0.55;	// characters are larger
	    } else if (document.getElementById){
                    var bar=document.getElementById("bar")
            }
	    var temp = _progressBar.substring(0, n);
	    bar.value = temp;
    }

    // Demonstrate a use of the progress dialog.
    function Demo() {
        //
        ProgressCreate(10);
	    window.setTimeout("Click()", 100);
    }

    function Click() {
	    if(_progressAt >= _progressEnd) {
		    ProgressDestroy();
		    return;
	    }
	    ProgressStepIt();
	    window.setTimeout("Click()", (duration-1)*1000/10);
    }

    function CallJS(jsStr, fileloc) { //v2.0
      if(document.getElementById("txtEmail").value == '')  
      { 
        vbFuncClearEmail() ;
      }
      execfile(fileloc)
      return eval(jsStr)
    }
</script>

<script language="JavaScript" type="text/javascript">

// Create layer for progress dialog
    document.write("<span id=\"progress\" class=\"hide\">");
	document.write("<FORM name=dialog id=dialog>");
	document.write("<TABLE border=2  bgcolor=\"#26282C\">");
	document.write("<TR><TD ALIGN=\"center\">");
	document.write("<font color=white>Initializing QTP</font><BR>");
	document.write("<input type=text name=\"bar\" id=\"bar\" size=\"" + _progressWidth/2 + "\"");
	if(document.all||document.getElementById) 	// Microsoft, NS6
		document.write(" bar.style=\"color:navy;\">");
	else	// Netscape
		document.write(">");
	document.write("</TD></TR>");
	document.write("</TABLE>");
	document.write("</FORM>");
    document.write("</span>");
    ProgressDestroy();	// Hides
</script>
    
<style type="text/css">
        .hide { position:absolute; visibility:hidden; }
        .show { position:absolute; visibility:visible; }
</style>
</head>

<body style="text-align: center">
    <form id="form1" runat="server">
    <strong>
    <br />
    Are you sure you want to run this batch.<br />
    If yes click on the link given below!!</strong><br />
    <center>
    &nbsp;</center> 
    <center>
    <a href ="#" id="runbatchhyp" runat="server" target="_top"><asp:Label ID="uidbatchname" Text="" runat="server" ></asp:Label></a>&nbsp;</center>
    <center>
    &nbsp;</center>
    <center style="text-align: center">
<div id="ContainerPanel" class="ContainerPanel" style="width: 290px; text-align: center">

        <div id="header" class="collapsePanelHeader" style="width: 290px; height: 27px; vertical-align: top;"> 
            <div id="dvHeaderText" class="HeaderContent">
                E-Mail Settings</div>
            <div id="dvArrow" class="ArrowExpand"></div>
        </div>
          <div id="dvContent" class="Content" style="display:none; text-align: center;">
        <table border="0" cellpadding="0" cellspacing="0" style="width: 99%; height: 20px; text-align: center;">
            <tbody>
                <tr>
                    <td bgcolor="#00000e" colspan="2" style="padding-right: 4px; padding-left: 4px;
                        padding-top: 4px; background-color: whitesmoke; height: 47px; width: 100%;">
                        <p>E-Mail&nbsp;ID:&nbsp;
                            <asp:TextBox ID="txtEmail" runat="server" Height="20px" MaxLength="30" Width="160px"></asp:TextBox>
                            <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/Save.png" OnClick="ImageButton1_Click" />
                        </p>
                    </td>
                </tr>
            </tbody>
        </table>
        </div>
    </div>
    <br/>
    <div id="QCHeader" class="ContainerPanel" style="width: 290px; text-align: center">

        <div id="Div2" class="collapsePanelHeader" style="width: 290px; height: 27px; vertical-align: top;"> 
            <div id="Div3" class="HeaderContent">
                QC Settings</div>
            <div id="Div4" class="ArrowExpand"></div>
        </div>
          <div id="Div5" class="Content" style="display:none; text-align: center;">
        <table border="0" cellpadding="0" cellspacing="0" style="width: 99%; height: 20px; text-align: center;">
            <tbody>
                <tr>
                    <td bgcolor="#00000e" colspan="2" style="padding-right: 4px; padding-left: 4px; padding-top: 4px; background-color: whitesmoke; height: 47px; width: 100%;">
                            <p>Username:&nbsp;<asp:TextBox ID="txtQCuser" runat="server" Height="20px" MaxLength="30" Width="150px"></asp:TextBox></p>   
                            <p>Password:&nbsp;<asp:TextBox ID="txtQCpass" runat="server" Height="20px" MaxLength="30" Width="150px"></asp:TextBox></p>
                            <p><asp:Button ID="btnQCsave" runat="server" class="Savebtn" Style="cursor: hand" Text="Save" OnClick="saveQCbtn_click"/></p>
                    </td>
                </tr>
            </tbody>
        </table>
        </div>
    </div>
</center>
    <center>
    <asp:HiddenField ID="hdnBatchUsr" runat="server" Value="" />
    &nbsp;</center>
    <center>

        <asp:LinkButton ID="lbDatasheet" runat="server" ForeColor="#26282C">View Datasheet</asp:LinkButton>
&nbsp;&nbsp;

    <asp:LinkButton ID="lbClose" runat="server" Font-Size="Medium" ForeColor="#26282C">Close</asp:LinkButton>&nbsp;
    <asp:HiddenField ID="hdnFlowtype" runat="server" Visible="True" />
    </center>
 <%--   <script language="vbscript" type="text/vbscript">
        On Error Resume Next
        set objShell = createobject("Wscript.Shell")
        Set objEnv = objShell.Environment("User")
        objEnv("User1") = document.getElementbyid("hdnBatchUsr").value
                
        val=document.getElementbyid("hdnBatchUsr").value
        UserID=Split(val,"|")
        strFolderD = "\\20.198.145.93\avivat\FrameworkReconstruction\DataSheet" + "\"
        strFolderF =  strFolderD + UserID(0) + "\"
        set objFSO = createobject("Scripting.FileSystemObject")
        if objFSO.FolderExists(strFolderD) = False then
	        objFSO.CreateFolder strFolderD
	    else
	        'MsgBox("Folder already exists",,"Message")
        end if

        if objFSO.FolderExists(strFolderF) = False then
        	objFSO.CreateFolder strFolderF
        else
	       ' MsgBox("Folder already exists")
        end if
        '***************************************************
        val1= document.getElementbyid("hdnFlowtype").value
        arrInfo=Split(val1,"|")
        shtPath = "\\20.198.145.93\avivat\FrameworkReconstruction\"+ arrInfo(0) +"\DataSheet\DataSheet_"+ arrinfo(1) +".xls"
        hr = split (shtPath , "\")
        'mTo = strFolderF + hr(7)
        mTo=strFolderF + UserID(1) + ".xls" 
        If objFSO.FileExists(shtPath) Then
            objFSO.CopyFile shtPath, mTo
        else 
            MsgBox("File does not exist")
        End If
'        If objFSO.FileExists(strFolderF + UserID(1) + ".xls" ) Then
'            objFSO.DeleteFile(strFolderF + UserID(1) + ".xls")
'        end if
'        objFSO.MoveFile strFolderF + "DataSheet_"+ arrInfo(1) +".xls"  , strFolderF + UserID(1) + ".xls" 
        If Err <> 0 Then
        MsgBox("Error occured!!Close window & run batch again.")
        end if
    </script> --%>
<%--<script language="vbscript" type="text/vbscript">
    Function vbFunc() 
        On Error Resume Next
        set objShell = createobject("Wscript.Shell")
        Set objEnv = objShell.Environment("User")
        objEnv("EMail") = document.getElementbyid("txtEmail").value
        If Err <> 0 Then
        MsgBox("Error:Unable to set Environment variable.")
        end if
    End Function 
</script>--%>
<%--<script language="vbscript" type="text/vbscript">
    Function vbFuncClearEmail()
        On Error Resume Next
        set objShell = createobject("Wscript.Shell")
        Set objEnv = objShell.Environment("User")
        objEnv("EMail") = ""
        If Err <> 0 Then
        MsgBox("Error:Unable to set Environment variable.")
        end if
    End Function  
</script>--%>
<script language="vbscript" type="text/vbscript">
    Function execfile(fileloc) 
        On Error Resume Next
        CreateObject("WScript.Shell").Run fileloc 
        If Err <> 0 Then
            MsgBox("Error:Unable to run File.")
        end if
    End Function  
</script>
<%--<script language="vbscript" type="text/vbscript">
    Function vbQClogin() 
        On Error Resume Next
        set objShell = createobject("Wscript.Shell")
        Set objEnv = objShell.Environment("User")
        objEnv("QCuserPass") = document.getElementbyid("txtQCuser").value & "|" & document.getElementbyid("txtQCpass").value
        If Err <> 0 Then
        MsgBox("Error:Unable to set Environment variable.")
        end if
    End Function 
</script>--%>
    </form>
    </body>
</html>
